package com.luchao.jsoup;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.io.IOException;
import java.net.URL;

/**
 * 元气壁纸采集
 * https://bizhi.cheetahfun.com/
 */
public class HtmlParseUtilYuanqi {
    private static Integer num = 10;

    public static void main(String[] args) throws IOException {
        //类型
        String url = "";
        //页数
        Integer num = 112;
        for (int i = 1; i <= num; i++) {
            url = "https://bizhi.cheetahfun.com/d_3/index_" + i + ".shtml";
            try {
                Wallpaper(url);
            } catch (Exception e) {
                continue;
            }
        }
    }

    /**
     * 动漫  https://bizhi.cheetahfun.com/d_1/index_6.shtml    1-112
     * 动物  https://bizhi.cheetahfun.com/d_6/index_2.shtml    1-112
     * 明星  https://bizhi.cheetahfun.com/d_7/index_111.shtml   1-112
     * 汽车  https://bizhi.cheetahfun.com/d_12/index_1.shtml   1-9 ？？？
     * 游戏  https://bizhi.cheetahfun.com/d_8/index_2.shtml   1-112
     * 科幻  https://bizhi.cheetahfun.com/d_5/index_2.shtml   1-112
     * 美女  https://bizhi.cheetahfun.com/d_3/index_2.shtml  1-112
     * 风景  https://bizhi.cheetahfun.com/d_2/index_2.shtml  1-112
     *
     *
     * 壁纸下载
     *
     * @throws IOException
     */
    private static void Wallpaper(String url) throws IOException {
        Document document = Jsoup.parse(new URL(url), 30000);
        Elements element = document.getElementsByTag("video");
        for (Element element1 : element) {
//            System.out.println("+" + element1.toString());
            String estr = element1.toString();
            String urlStr = estr.substring(estr.indexOf("data-src=") + 10, estr.indexOf("\" muted"));
            System.out.println(urlStr);
        }
    }

}
